package com.gzr.demo01;

import java.util.concurrent.*;

public class TestCallable implements Callable<Boolean> {

    private String name;

    public TestCallable(String name) {
        this.name = name;
    }

    @Override
    public Boolean call() throws Exception {
        System.out.println("下载文件名称："+name);
        return true;
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //创建三个线程
        TestCallable t1 = new TestCallable("文件1");
        TestCallable t2 = new TestCallable("文件2");
        TestCallable t3 = new TestCallable("文件3");

        // 创建执行服务
        ExecutorService ser = Executors.newFixedThreadPool(3);
        // 提交执行
        Future<Boolean> result1 = ser.submit(t1);
        Future<Boolean> result2 = ser.submit(t2);
        Future<Boolean> result3 = ser.submit(t3);
        // 获取结果
        boolean res1 = result1.get();
        boolean res2 = result2.get();
        boolean res3 = result3.get();
        // 关闭服务
        ser.shutdown();
    }
}
